<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/6/27
 * Time: 4:38 PM
 */
namespace app\common\models;

class UserRole extends BaseModel
{
    public $table = 'yq_user_role';
    public $timestamps = false;
    protected $guarded = [''];

    public function role()
    {
        return $this->hasOne(Role::class,'id','role_id');
    }

    /*
     * 每一个角色 role_id 有多个权限，type = 2 的为角色权限，item_id 此时为角色ID
     * */
    public function permissions()
    {
        return $this->hasMany(Permission::class,'item_id','role_id')
            ->where('type','=', Permission::TYPE_ROLE);
    }
    //用户有一个主部门
    public function mainDepartment()
    {
        return $this->hasOne(Department::class, 'id', 'main_department_id');
    }

}